/*
 * @Author: your name
 * @Date: 2021-07-28 18:09:28
 * @LastEditTime: 2021-07-28 18:26:37
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \flutter_data_center\lib\screens\app\welcome_video.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/utills/log_utils.dart';
import 'package:video_player/video_player.dart';

class WelcomeVideoWidget extends StatefulWidget {
  @override
  _WelcomeVideoWidgetState createState() => _WelcomeVideoWidgetState();
}

class _WelcomeVideoWidgetState extends State<WelcomeVideoWidget> {
  VideoPlayerController _controller;
  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.asset("assets/video/welcome1.mp4")
      ..initialize().then((_) {
        _controller.setLooping(true);
        LogUtils.e("视频加载完成");
        _controller.play();
        setState(() {});
      });
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return _controller.value.isInitialized
        ? SizedBox(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: AspectRatio(
              aspectRatio: _controller.value.aspectRatio,
              child: VideoPlayer(_controller),
            ),
          )
        : Container();
  }
}
